package com.hnkywl.sts.action.sys;


import com.hnkywl.sts.entity.sys.Qx;
import com.hnkywl.sts.service.sys.QxService;
import net.ruixin.web.struts2.SimpleActionSupport;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.springframework.beans.factory.annotation.Autowired;


/**
 * 说明：
 * 包:        com.hnkywl.sts.action.sys
 * 类描述:    权限Action类
 * 修改备注: [说明本次修改内容]
 * 版本:        [v1.0]
 */
@Namespace("/sys/qx")
public class QxAction extends SimpleActionSupport {
    private QxService qxService;
    //查询条件：权限
    private Qx qx;
    //传入的Id值
    private Long qxId;
    //权限名称
    private String mc;
    //分页组件 起始位置
    private int page;
    //分页组件 页面大小
    private int rows;
    //行索引
    private int index;
    //远程ajax验证的值
    private String validateVal;
    //需要远程ajax验证的属性
    private String validateField;
    /**
     * 查询权限列表
     */
    @Action("qxList")
    public void qxList() {
        this.renderJson(this.qxService.findAllQx(mc, page, rows));
    }

    /**
     * 显示权限名称列表可供选择
     *
     * findQxMc(String qxmc, int pageNo, int pageSize)
     * pageNo:         页数
     * pageSize:      行数
     * 查找所有权限名称
     */
    @Action("qxmcList")
    public void qxmcList() {
        this.renderJson(this.qxService.findAllQxmc(mc, 0,-1));
    }

    /**
     * 方法名:     判断增加还是修改
     * 功能描述:      判断增加还是修改
     * 异常:      <RuntimeException  Exception>
     * 创建人:     hl
     * 创建日期:   13-2-19上午10:47
     * 修改人:     hl
     * 修改日期:   13-2-19上午10:47
     */
    @Action("qx_content")
    public String qxContent() {
        if(qxId!=null)
            qx = qxService.findQxDetail(qxId);
        return SUCCESS;
    }

    /**
     * 方法名:     add_qx
     * 功能描述:   添加权限
     * 输入参数:
     * 异常:      <RuntimeException  Exception>
     * 创建人:     hl
     * 创建日期:   13-3-11上午11:50
     * 修改人:     hl
     * 修改日期:   13-3-11上午11:50
     */
    @Action("add_qx")
    public void addQx() {
        try {
            qxService.saveQx(qx);
            renderText("{\"statusCode\":\"200\", \"message\":\"保存权限信息成功\", \"operationType\":\"add\"}");
        } catch (Exception e) {
            e.printStackTrace();
            renderText("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }
    }

    /**
     * 方法名:     delete_qx
     * 功能描述:    删除权限
     * 输入参数:
     * 异常:      <RuntimeException  Exception>
     * 创建人:     hl
     * 创建日期:   13-3-11上午11:50
     * 修改人:     hl
     * 修改日期:   13-3-11上午11:50
     */
    @Action("delete_qx")
    public void deleteQx() {
        try {
            qxService.deleteQx(qxId);
            renderText("{\"statusCode\":\"200\", \"message\":\"删除权限信息成功\", \"operationType\":\"delete\"}");
        } catch (Exception e) {
            e.printStackTrace();
            renderText("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }
    }
    /**
     * 远程ajax验证
     */
    @Action("ajax_validate")
    public void ajaxValidate() {
        if (!qxService.ajaxValidate(qxId,validateVal,validateField))
            renderJson("{\"valid\":true}");
        else
            renderJson("{\"valid\":false}");
    }
    //================setter getter=========================
    public String getMc() {
        return mc;
    }

    public void setMc(String mc) {
        this.mc = mc;
    }

    public Qx getQx() {
        return qx;
    }

    public void setQx(Qx qx) {
        this.qx = qx;
    }

    public Long getQxId() {
        return qxId;
    }

    public void setQxId(Long qxId) {
        this.qxId = qxId;
    }

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public int getRows() {
        return rows;
    }

    public void setRows(int rows) {
        this.rows = rows;
    }

    public int getIndex() {
        return index;
    }

    public void setIndex(int index) {
        this.index = index;
    }

    public String getValidateVal() {
        return validateVal;
    }

    public void setValidateVal(String validateVal) {
        this.validateVal = validateVal;
    }

    public String getValidateField() {
        return validateField;
    }

    public void setValidateField(String validateField) {
        this.validateField = validateField;
    }

    @Autowired
    public void setQxService(QxService qxService) {
        this.qxService = qxService;
    }
}
